const { contextBridge, ipcRenderer } = require('electron');

// Expose protected methods that allow the renderer process to use
// the ipcRenderer without exposing the entire object
contextBridge.exposeInMainWorld('electronAPI', {
  /**
   * Vocabulary APIs
   */
  getWord: word => ipcRenderer.invoke('vocabulary:get', word),
  searchWords: pattern => ipcRenderer.invoke('vocabulary:search', pattern),
  searchWordsByPrefix: ({ prefix, limit }) => ipcRenderer.invoke('vocabulary:search-prefix', { prefix, limit }),
  searchWordsBySuffix: ({ suffix, limit }) => ipcRenderer.invoke('vocabulary:search-suffix', { suffix, limit }),
  searchSimilarWords: ({ word, limit }) => ipcRenderer.invoke('vocabulary:search-similar', { word, limit }),
  getWords: ({ limit, offset }) => ipcRenderer.invoke('vocabulary:list', { limit, offset }),
  addQueryHistory: word => ipcRenderer.invoke('vocabulary:add-history', word),
  getQueryHistory: limit => ipcRenderer.invoke('vocabulary:get-history', limit),
  clearQueryHistory: () => ipcRenderer.invoke('vocabulary:clear-history'),
  removeQueryHistoryItem: word => ipcRenderer.invoke('vocabulary:remove-history-item', word),
  updateKnownStatus: ({ word, status }) => ipcRenderer.invoke('vocabulary:update-known-status', { word, status }),
  updateIeltsTag: ({ word, tag }) => ipcRenderer.invoke('vocabulary:update-ielts-tag', { word, tag }),

  /**
   * Learning Progress APIs
   */
  getLearningStatistics: () => ipcRenderer.invoke('learning-progress:get-statistics'),
  getLearningHistory: limit => ipcRenderer.invoke('learning-progress:get-history', limit),

  /**
   * Pronunciation APIs
   */
  playPronunciation: audioPath => ipcRenderer.invoke('pronunciation:play', { audioPath }),
  stopPronunciation: () => ipcRenderer.invoke('pronunciation:stop'),
});